﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;

namespace DataApi
{
    public static class EpicMvcHelper
    {
        /// <summary>
        /// Registers routes based on the strings set in the Constants class
        /// </summary>
        /// <param name="routes">The route collection to map the routes to</param>
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.MapRoute(
                name: EpicCmsConstants.RunMethodRoute,
                url: EpicCmsConstants.RunMethodUrl,
                defaults: new
                {
                    controller = EpicCmsConstants.RunMethodController,
                    action = EpicCmsConstants.RunMethodAction
                }
            );

            routes.MapRoute(
                name: EpicCmsConstants.GetDataByIdRoute,
                url: EpicCmsConstants.GetDataByIdUrl,
                defaults: new
                {
                    controller = EpicCmsConstants.GetDataByIdController,
                    action = EpicCmsConstants.GetDataByIdAction
                }
            );

            routes.MapRoute(
                name: EpicCmsConstants.GetDataRoute,
                url: EpicCmsConstants.GetDataUrl,
                defaults: new
                {
                    controller = EpicCmsConstants.GetDataController,
                    action = EpicCmsConstants.GetDataAction,
                    id = UrlParameter.Optional
                }
            );

            routes.MapRoute(
                name: EpicCmsConstants.GetDataHeaderRoute,
                url: EpicCmsConstants.GetDataHeaderUrl,
                defaults: new
                {
                    controller = EpicCmsConstants.GetDataHeaderController,
                    action = EpicCmsConstants.GetDataHeaderAction,
                    id = UrlParameter.Optional
                }
            );

            routes.MapRoute(
                name: EpicCmsConstants.GetAliasDataRoute,
                url: EpicCmsConstants.GetAliasDataUrl,
                defaults: new
                {
                    controller = EpicCmsConstants.GetAliasDataController,
                    action = EpicCmsConstants.GetAliasDataAction,
                    id = UrlParameter.Optional
                }
            );

            routes.MapRoute(
                name: EpicCmsConstants.CreateRoute,
                url: EpicCmsConstants.CreateUrl,
                defaults: new
                {
                    controller = EpicCmsConstants.CreateController,
                    action = EpicCmsConstants.CreateAction,
                    type = UrlParameter.Optional,
                    name = UrlParameter.Optional,
                    id = UrlParameter.Optional
                }
            );

            routes.MapRoute(
                name: EpicCmsConstants.ControllerRoute,
                url: EpicCmsConstants.ControllerUrl,
                defaults: new
                {
                    action = EpicCmsConstants.DefaultAction,
                    name = UrlParameter.Optional,
                    id = UrlParameter.Optional
                }
            );

            routes.MapRoute(
                name: EpicCmsConstants.DefaultRoute,
                url: EpicCmsConstants.DefaultUrl,
                defaults: new
                {
                    controller = EpicCmsConstants.DefaultController,
                    action = EpicCmsConstants.DefaultAction,
                    type = UrlParameter.Optional,
                    name = UrlParameter.Optional,
                    id = UrlParameter.Optional
                }
            );
        }

        /// <summary>
        /// Adds the required js and css bundles 
        /// </summary>
        /// <param name="Bundles">The bundle collection to add the bundles to</param>
        public static void AddBundles(BundleCollection Bundles)
        {
            var DataApiJs = new Bundle("~/Scripts/EpicCms", new NoTransform());
            DataApiJs.AddFile("~/Scripts/jquery-1.7.2.min.js");
            DataApiJs.AddFile("~/Scripts/jquery.resize.js");
            DataApiJs.AddFile("~/Scripts/jquery.mousewheel.min.js");
            DataApiJs.AddFile("~/Scripts/DataManager.js");
            DataApiJs.AddFile("~/Scripts/jquery.grid.js");
            DataApiJs.AddFile("~/Scripts/jquery.grideditor.js");
            Bundles.Add(DataApiJs);
        }
        
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
        }
    }
}